﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AAA.Database;
using AAA.ResultSet;

namespace AAA.DataLoader
{
    public abstract class AbstractLoader : ILoader
    {
        #region ILoader Members

        private IDatabase _database;
        private string _strErrorMessage;
        private Dictionary<string, string> _dicLoaderParam;
        private bool _isSuccess;

        public AbstractLoader()
        {
            _dicLoaderParam = new Dictionary<string, string>();
        }

        public IDatabase Database
        {
            get
            {
                return _database;
            }
            set
            {
                _database = value;
            }
        }

        public string ErrorMessage
        {
            get
            {
                return _strErrorMessage;
            }
            set
            {
                _strErrorMessage = value;
            }
        }

        public bool IsSuccess
        {
            get { return _isSuccess; }
            set { _isSuccess = value; }
        }

        public void AddLoaderParam(string strKey, string strValue)
        {
            if (_dicLoaderParam.ContainsKey(strKey))
                _dicLoaderParam[strKey] = strValue;
            else
                _dicLoaderParam.Add(strKey, strValue);
        }

        public void SetLoaderParam(string strKey, string strValue)
        {
            if (_dicLoaderParam.ContainsKey(strKey))
                _dicLoaderParam[strKey] = strValue;
            else
                _dicLoaderParam.Add(strKey, strValue);
        }

        public string GetLoaderParam(string strKey)
        {
            return _dicLoaderParam.ContainsKey(strKey)
                    ? _dicLoaderParam[strKey]
                    : null;
        }

        public abstract bool Load(IResultSet resultSet);

        #endregion
    }
}
